package com.itheima.test;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Dom4jDemo2 {
    public static void main(String[] args) throws DocumentException {
        //获取核心解析器对象
        SAXReader reader = new SAXReader();
        //解析xml获取document对象
        Document document = reader.read(Dom4jDemo2.class.getClassLoader().getResourceAsStream("student.xml"));
        //获取根标签
        Element rootElement = document.getRootElement();
        //获取根标签name属性值
        String name = rootElement.attributeValue("name");
        //获取子标签   第二个子标签
        Element element = (Element) rootElement.elements().get(1);
        //获取
        Element sex = element.element("sex");
        //获取纯文本内容
        String text = sex.getText();
        System.out.println(text);

    }
}
